<template>
  <div class="commonDetail">
    <el-row :gutter="20">
      <el-col
        v-for="(item, index) in definition"
        v-if="exist(item)"
        :span="item.colSpan || colSpan"
        :key="index + '-' + item.label"
      >
        <contentItem
          class="contentItem"
          :class="'contentItem' + item.key"
          :item="item"
          :content="at(data, item.key)[0]"
          :data="data"
        ></contentItem>
        <slot :name="item.key"></slot>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import contentItem from "./contentItem";
let { at } = require("lodash");
export default {
  components: { contentItem },
  props: {
    colSpan: {
      default: 8,
    },
    data: {
      type: Object,
      default: () => {
        return {};
      },
    },
    definition: {
      type: Array,
      default: () => {
        return {};
      },
    },
  },
  data() {
    this.at = at;
    return {};
  },
  methods: {
    exist(item) {
      let v = item.exist;
      let content = at(this.data, item.key)[0];
      if (v || v === false || v === 0) {
        if (typeof v === "function") {
          return v(content, this.data);
        } else {
          return v;
        }
      } else {
        return true;
      }
    },
  },
};
</script>
<style scoped>
.el-col {
  display: flex;
}
.el-col .contentItem {
  overflow: hidden;
}
</style>
